<template>
  <div class="course shadow" @click="goDetail(Number(id))">
    <div class="iconPathBox">
      <img :src="img" lazy="loaded">
    </div>
    <div class="name">{{ name }}</div>
    <div class="desc"> 简介：{{ desc }}</div>
    <div class="time"> 上课时间：{{date1 }} ~ {{ date2 }}</div>
  </div>
</template>

<script setup>

  import { useRoute, useRouter } from "vue-router";

  let route = useRoute()
  let router = useRouter()
  const props = defineProps(['name', 'desc', 'time1', 'time2', 'img', 'id'])
  const time1 = new Date(props.time1);

  // 提取日期部分
  const date1 = time1.toISOString().split("T")[0];
  const time2 = new Date(props.time2);

  // 提取日期部分
  const date2 = time2.toISOString().split("T")[0];

  const goDetail = (id, number) => {
    router.push({ path: 'details', query: { corId: id } })
  }
</script>

<style>
  .course {
    cursor: pointer;
    padding: 4px 10px 0;
    margin-bottom: 15px;
    margin-left: 30px;
    margin-right: 30px;
    width: 240px;
    height: 270px;
    background-color: #fff;
    border-radius: 8px;
    border: 1px solid #fff;
  }

  .shadow {
    box-shadow: 0 1px 5px 0 rgba(0, 0, 0, .16);
    transition: box-shadow .2s linear;
  }

  .desc,
  .name {
    word-break: break-all;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .name {
    margin-top: 8px;
    font-family: Segoe UI;
    font-size: 18px;
    color: #707070;
  }

  .time {
    font-family: Segoe UI;
    font-size: 14px;
  }

  .iconPathBox img {
    -o-object-fit: cover;
    object-fit: cover;
    width: 220px;
    height: 135px;
    border-radius: 8px;
  }

  .iconBox img {
    margin-left: 80px;
    margin-top: 20px;
  }

  img {
    vertical-align: middle;
    border-style: none;
    width: 70px;

  }

  .iconBox {
    background: url(../../assets/logos.png);
    margin-left: 80px;
    margin-top: 20px;
    background-size: cover;
    height: 50px;
    width: 50px;
  }
</style>